<!--
 * @description: 文件描述
 * @version: 0.0.1
 * @author: xxx
 * @Date: 2025-02-27 09:57:16
-->
<script setup>
import { ref, computed, onMounted } from "vue";
import { useRoute,useRouter } from 'vue-router';
const router = useRouter();
const route = useRoute();
// 从路由配置中动态获取菜单项
const menuRoutes = computed(() => {
  return router.getRoutes()
    .filter(r => r.meta.showInMenu) // 只显示带特定meta的路由
    .sort((a, b) => (a.meta.menuOrder || 0) - (b.meta.menuOrder || 0));
});

// 优化激活项计算
const activeIndex = computed(() => {
  return menuRoutes.value.findIndex(item => 
    item.name === route.name || route.path.startsWith(item.path)
  ) + 1 + '';
});

// 导航方法保持不变
const navigate = (path) => {
  router.push(path);
};
</script>

<template>
  <el-card body-style="padding:0;" class="aside-card">
    <el-aside width="200px">
      <el-menu :default-active="activeIndex" class="aside-menu">
        <el-menu-item 
          v-for="(item, index) in menuRoutes"
          :key="index"
          :index="(index + 1).toString()"
          @click="navigate(item.path)"
        >
          <el-icon class="menu-icon">
            <component :is="item.meta.icon" />
          </el-icon>
          <span>{{ item.meta.title }}</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
  </el-card>
</template>

<style scoped>
.aside-card {
  height: 100%;
  border-radius: 0;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
  background: linear-gradient(to bottom, #ffffff, #f8f9fa);
}

.aside-menu {
  height: 100%;
  border-right: none;
  background-color: transparent;
  padding: 12px 0;
}

.menu-icon {
  font-size: 18px;
  margin-right: 12px;
  color: #606266;
  transition: all 0.3s ease;
}

.el-menu-item {
  height: 50px;
  line-height: 50px;
  margin: 4px 12px;
  border-radius: 6px;
  transition: all 0.3s ease;
}

.el-menu-item:hover {
  background-color: #f0f2f5;
  color: #409eff;
}

.el-menu-item:hover .menu-icon,
.el-menu-item.is-active .menu-icon {
  color: #409eff;
  transform: scale(1.1);
}

.el-menu-item.is-active {
  background-color: #ecf5ff;
  color: #409eff;
  font-weight: 500;
  border-right: none;
  position: relative;
}

.el-menu-item.is-active::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 24px;
  background-color: #409eff;
  border-radius: 3px;
}
</style>
